﻿@using FwProject.Distribution.Dto
@using FwProject.Settlement.Dto
@using FwProject.ManagerConfig.Dto
@using FwProject.Comm
@model List<SettlementInfoPrintDto>
@{

    ConfigInfoDto config = ViewBag.Config;
}

<style type="text/css">

    .input-group[class*=col-] {
        padding: 0 15px;
    }

    .Noprint {
        display: none;
    }

    .PageNext {
        page-break-after: always;
    }

    * {
        word-wrap: break-word;
        word-break: break-all;
    }

    table {
        border-collapse: collapse;
        border-spacing: 0px;
    }

    .column_set_div {
        display: inline-block;
        position: fixed;
        background: #ffffff;
        top: 100px;
        left: 10px;
        width: 120px;
        overflow: auto;
        border: 1px black solid;
    }

        .column_set_div table {
            width: 100%;
            border-collapse: collapse;
        }

            .column_set_div table th {
                background-color: #E6E6E6;
                padding: 3px 3px;
                white-space: nowrap;
            }

            .column_set_div table td {
                white-space: nowrap;
                padding: 0px 3px;
            }

        .column_set_div button {
            padding: 0px 10px;
            margin: 4px 4px;
            border: #ccc 1px outset;
        }

    .gzImg {
        filter: alpha(opacity=80);
        -moz-opacity: 0.8;
        width: auto !important;
        width: 100%
    }
</style>
<object id="WebBrowser" classid="clsid:8856F961-340A-11D0-A96B-00C04FD705A2" height="0" width="0" style="display: none"></object>
<div align="center">
    <input type="button" value="隐藏收据" onclick="showOrHide(this)">
    <input type="button" value="打印" onclick="window.print()">
    <input type="button" value="打印预览" onclick="document.all.WebBrowser.ExecWB(7,1)">
</div>
<form name="printformName" id="printformName" action="" method="post">
    <div align="center">
        <div id="printObj" style="width: 190mm" align="center">
            <div align="center" style="font-size: 14px; margin-top: 3px; margin-bottom: 15px; font-weight: bold;">
            </div>
            @foreach (var item in Model)
            {
                <table name="mainTable" style="width:100%;height:auto;text-align: center;margin-bottom:0px;margin-top:10px;" border="0">
                    <!--<table name="mainTable"  style="width:100%;height:auto;text-align: center;margin-bottom:0px;margin-top:1px;" border="0" >-->
                    <tbody>
                        <tr receiptmain="1">
                            <td align="center" style="width:100%;">
                                <table cellspacing="0" cellpadding="0" style="width: 600px">
                                    <tbody>
                                        <tr>
                                            <td align="center" width="100%" style="font-size: 22px;color:#000000;height: 35px;padding-top: 10px;" colspan="3">
                                                @config?.CorporateName
                                            </td>
                                        </tr>
                                        <tr>
                                            <td nowrap="nowrap" align="left" width="50%" style="font-size: 14px;color:#000000;height: 35px">
                                                地址：@config?.CorporateAddress
                                            </td>
                                            <td nowrap="nowrap" align="right" width="50%" style="font-size: 14px;color:#000000;height: 35px;padding-right:150px">
                                                电话：@config?.CorporateMobile&nbsp;&nbsp;
                                            </td>
                                            <td style="position:relative;"></td>
                                        </tr>
                                        <tr>
                                            <td align="center" width="100%" style="font-size: 22px;color:#000000;height: 20px" colspan="3">
                                                收&nbsp;&nbsp;款&nbsp;&nbsp;收&nbsp;&nbsp;据
                                            </td>
                                        </tr>
                                        <tr>
                                            <td align="center" colspan="2" width="100%" style="height: 20px">
                                                @item.CreationTime&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;No&nbsp;<span id="number">@item.CreationNumber</span>
                                            </td>
                                            <td rowspan="2" align="right">
                                                <div style="color:#000000;font-size:12px;line-height:12px;width:5px;margin-right:-10px;margin-top:10px;">
                                                    一联存根<br><br>二联餐厅<br><br>三联记账
                                                </div>
                                            </td>
                                        </tr>
                                        <tr>
                                            <td align="left" colspan="3">
                                                <table name="justForJeDis" align="left" width="100%" cellspacing="0" cellpadding="0" style="border:1px solid #000000;">
                                                    <tbody>
                                                        <tr>
                                                            <td align="center" style="color: #000000;font-size: 16px;width: 100px;">今&nbsp;&nbsp;收&nbsp;&nbsp;到</td>
                                                            <td align="left" style="width:500px;border-bottom: 1px solid #000000;height: 35px;font-size: 14px">
                                                                <span>@item.RestaurantInfoModel.RestaurantName</span>&nbsp;<label index="16" text="餐厅编号" style="display: none;">010062&nbsp;</label>@(item.MonthBegin)月份餐具（@item.DeliveryDate）
                                                            </td>
                                                        </tr>
                                                        <tr>
                                                            <td align="center" style="color: #000000;font-size: 16px;">配&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;送</td>
                                                            <td width="500px">
                                                                @{var t = item.TypeNumber.GroupBy(g => new { g.TypeNumberPrice, g.TypeNumberName }).Select(s => new
                                                                    {
                                                                        TypeNumberName = s.Key.TypeNumberName,
                                                                        DistributionBoxCount = s.Sum(msum => msum.DistributionBoxCount),
                                                                        DistributionCount = s.Sum(msum => msum.DistributionCount),
                                                                        TypeNumberPrice = s.Key.TypeNumberPrice,
                                                                        SumPrice = s.Sum(msum => msum.SumPrice)

                                                                    }); }

                                                                @foreach (var temp in t)
                                                                {
                                                                    <table align="left" width="100%" cellspacing="0" cellpadding="0">

                                                                        <tbody>
                                                                            <tr>
                                                                                <td nowrap="" width="100%" align="left" style="border-bottom: 1px solid #000000;height:                                              35px;font-size: 14px;">
                                                                                    @temp.TypeNumberName：

                                                                                    @temp.DistributionBoxCount
                                                                                    箱

                                                                                    =&nbsp; <span name="slQuaPs">@temp.DistributionCount</span>
                                                                                    套

                                                                                    x&nbsp;@temp.TypeNumberPrice
                                                                                    =&nbsp;<span name="jeMoney">@temp.SumPrice</span>元
                                                                                </td>
                                                                            </tr>

                                                                        </tbody>
                                                                    </table>
                                                                }

                                                            </td>
                                                        </tr>

                                                        <tr><td style='color: #000000;font-size: 16px;width: 100px;'>&nbsp;优&nbsp;惠&nbsp;金&nbsp;额&nbsp;</td><td align='left' style='border-bottom: 1px solid #000000;height: 35px;font-size: 14px' colspan='2'>@item.Discountprice &nbsp;元</td></tr>

                                                        <tr>
                                                            <td align="center">
                                                                <div align="center" style="color: #000000;font-size: 16px;width: 100px;">
                                                                    <div>金&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;额</div>
                                                                    <div>人&nbsp;&nbsp;民&nbsp;&nbsp;币</div>
                                                                </div>
                                                            </td>
                                                            <td style="border-bottom: 1px solid #000000">
                                                                <table width="100%" cellspacing="0" cellpadding="0">
                                                                    <tbody>
                                                                        <tr>
                                                                            <td align="left" style="color: #000000;font-size: 16px;width: 60px;">(大写)</td>
                                                                            <td align="left" style="font-size: 16px;">
                                                                                <span name="jeAccountUpper"> @(CapitalHelper.CmycurD(item.Totalprice)) </span>&nbsp;&nbsp;&nbsp;
                                                                            </td>
                                                                        </tr>
                                                                    </tbody>
                                                                </table>
                                                            </td>
                                                        </tr>
                                                        <tr>
                                                            <td align="center" style="color: #000000;font-size: 16px;width: 100px;height: 40px;">
                                                                备&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;注
                                                            </td>
                                                            <td>
                                                                <table width="100%" cellspacing="0" cellpadding="0">
                                                                    <tbody>
                                                                        <tr>
                                                                            <td width="395px" style="font-size: 14px;height: 40px;" align="left"><div style="white-space: normal;"></div>@item.RemarksConten</td>
                                                                            <td nowrap="" style="border-left: 1px solid #000000;font-size: 16px;height: 40px;">
                                                                                &nbsp;￥
                                                                                <span width="100px" name="jeAccount">@(item.Totalprice - item.Discountprice)</span>元
                                                                            </td>
                                                                        </tr>
                                                                    </tbody>
                                                                </table>
                                                            </td>
                                                        </tr>
                                                    </tbody>
                                                </table>
                                            </td>
                                        </tr>

                                    </tbody>
                                </table>
                            </td>
                        </tr>
                        <tr receiptmain="1">
                            <td align="center" style="width:100%;">
                                <table cellspacing="0" cellpadding="0" style="width: 600px">
                                    <tbody>
                                        <tr align="left" width="100%">
                                            <td nowrap="nowrap" style="font-size: 14px;color:#000000;height: 30px;padding-right:50px;">
                                                单位盖章：
                                            </td>
                                            <td nowrap="nowrap" style="font-size: 14px;color:#000000;height: 25px;padding-right:10px;">会计：@config?.Accountant</td>
                                            <td nowrap="nowrap" style="font-size: 14px;color:#000000;height: 25px;padding-right:10px;">出纳：@config?.Cashier</td>
                                            <td nowrap="nowrap" style="font-size: 14px;color:#000000;height: 25px;">经手人：@config?.AgentPerson</td>
                                        </tr>
                                    </tbody>
                                </table>
                            </td>
                        </tr>
                        <tr>
                            <td>
                                <table cellspacing="0" cellpadding="0" align="center" border="1" bordercolor="black" width="618px">
                                    <thead class="thead">
                                        <tr>
                                            <td index="0" nowrap="" align="center" style="display: table-cell;"><b>日期</b></td>
                                            <td index="1" nowrap="" align="center" style="display: table-cell;"><b>货品</b></td>
                                            <td index="14" nowrap="" align="center" style="display: none;"><b>司机</b></td>
                                            <td index="2" nowrap="" align="center" style="display: table-cell;"><b>配送箱数</b></td>
                                            <td index="3" nowrap="" align="center" style="display: table-cell;"><b>配送套数</b></td>
                                            <td index="4" nowrap="" align="center" style="display: table-cell;"><b>回收箱数</b></td>
                                            <td index="5" nowrap="" align="center" style="display: table-cell;"><b>回收套数</b></td>
                                            <td index="6" nowrap="" align="center" style="display: table-cell;"><b>退回箱数</b></td>
                                            <td index="7" nowrap="" align="center" style="display: table-cell;"><b>退回套数</b></td>
                                            <td index="8" nowrap="" align="center" style="display: table-cell;"><b>换货数</b></td>
                                            <td index="9" nowrap="" align="center" style="display: table-cell;"><b>赠送数</b></td>
                                            <td index="10" nowrap="" align="center" style="display: table-cell;"><b>折损数</b></td>
                                            <td index="11" nowrap="" align="center" style="display: table-cell;"><b>单价(元)</b></td>
                                            <td index="12" nowrap="" align="center" style="display: table-cell;"><b>金额(元)</b></td>
                                            <td index="15" nowrap="" align="center" style="display: none;"><b>店存</b></td>
                                        </tr>
                                    </thead>
                                    <tbody class="tbody">
                                        @{ int m = 0;}
                                        @foreach (var y in item.TypeNumber)
                                        {
                                            m++;
                                        <tr>
                                            <td index="0" nowrap="" align="left" style="display: table-cell;">@y.DistributionDate.ToString("yyyy-MM-dd")</td>
                                            <td index="1" nowrap="" align="left" style="display: table-cell;">@y.TypeNumberName</td>
                                            <td index="14" nowrap="" align="right" style="display: none;"></td>
                                            <td index="2" nowrap="" align="right" style="display: table-cell;">@y.DistributionBoxCount</td>
                                            <td index="3" nowrap="" align="right" style="display: table-cell;">@y.DistributionCount</td>
                                            <td index="4" nowrap="" align="right" style="display: table-cell;">@y.RecoveryBoxCount</td>
                                            <td index="5" nowrap="" align="right" style="display: table-cell;">@y.RecoveryCount</td>
                                            <td index="6" nowrap="" align="right" style="display: table-cell;">@y.BackBoxCount</td>
                                            <td index="7" nowrap="" align="right" style="display: table-cell;">@y.BackCount</td>
                                            <td index="8" nowrap="" align="right" style="display: table-cell;">@y.ExchangeBoxCount</td>
                                            <td index="9" nowrap="" align="right" style="display: table-cell;">@y.GiveBoxCount</td>
                                            <td index="10" nowrap="" align="right" style="display: table-cell;">@y.DamageCount</td>
                                            <td index="11" nowrap="" align="right" style="display: table-cell;">
                                                @y.TypeNumberPrice
                                            </td>
                                            <td index="12" align="right" style="display: table-cell;">@y.SumPrice</td>
                                            @if (m == 1)
                                            {

                                                <td index="15" align="right" 5782845="" rowspan="@item.TypeNumber.Count()" style="display: none;">@item.Stock</td>
                                            }

                                        </tr>
                                        }

                                    </tbody>
                                </table>
                            </td>
                        </tr>
                    </tbody>
                </table>
            }
            <br>
        </div>
    </div>
</form>

<link href="/css/print.css" rel="stylesheet" />
<script src="~/js/Print.js"></script>
<script src="/Scripts/jquery-3.1.1.min.js"></script>

<script>
    var data = [];
    var ths = [];
    // var khKcLevel = opener.top.appOrgInfo.khKcLevel;
    var khKcLevel = 0;
    function getThs(thead) {
        var tds = thead.find("td");
        var result = {};
        result.columnCode = [];
        result.columnName = [];
        result.td = [];
        tds.each(function (i) {
            result.columnCode.push($(this).text());
            result.columnName.push($(this).text());
            //result.td.push($(this));
            var obj = {};
            obj.html = $(this);
            obj.index = $(this).attr("index");
            ths.push(obj);
        });
        ths.push({
            html: $("[index=16]"),
            index: 16
        });
        return result;
    }
    function createTip(list) {
        var div = $("<div class='column_set_div'><form><table border=1><thead><tr><th>列名</th><th>是否可见</th></tr></thead><tbody></tbody></table></form></div>");
        var tab = div.find("tbody");
        for (var i = 0; i < list.length; i++) {
            var obj = list[i];
            //明细库存不显示店存列
            if (khKcLevel == 1 && obj.columnCode == '店存') {
                obj.isShow = "0";
            }
            var c = (obj.isShow == "1" ? "checked" : "");
            var tr = $("<tr><td>" + obj.columnName + "</td><td width='1%' align='center'><input name='setColumnId' value='" + obj.setColumnId + "' type='hidden'><input name='columnCode' value='" + obj.columnCode + "' type='hidden'><input name='setId' value='" + obj.setId + "' type='hidden'><input name='isShow' value='" + obj.isShow + "' type='hidden'><input " + c + " type='checkbox'></td></tr>");
            //明细库存不显示店存设置
            if (khKcLevel == 1 && obj.columnCode == '店存') {
                tr.hide();
            }
            tab.append(tr);
        }
        var btns = $("<tr><td align='right' colspan=2><button  type='button' onclick='saveSet()'>确定</button></td></tr>");
        tab.append(btns);
        tab.find("input[type='checkbox']").click(function () {
            var t = $(this).parent().find("input[name='isShow']");
            if ($(this).is(':checked')) {
                t.val(1);
            } else {
                t.val(0);
            }
        });
        return div;
    }
    function showHideTd() {
        for (var a = 0; a < data.length; a++) {
            var index = -1;
            for (var i = 0; i < ths.length; i++) {
                if (ths[i].html.text() == data[a].columnName) {
                    index = ths[i].index;
                    break;
                } else {
                    var t = ths[i].html.attr("text");
                    if (t != null && t == data[a].columnName) {
                        index = ths[i].index;
                        break;
                    }
                }
            }
            if (index != -1) {
                if (data[a].isShow == "1") {
                    $("[index='" + index + "']").show();
                } else {
                    $("[index='" + index + "']").hide();
                }

            }
        }

    }
    function getColSet(func) {
        var a = $(".thead");
        if (a.length == 0) {
            return;
        } else {
            a = getThs($($(".thead")[0]));
        }
        a.listCode = "00#printDetailPsList";
        a.listName = "打印配送明细列表";
        var _this = this;
        $.ajax({
            traditional: true,
            type: "POST",
            url: "/print/GetPrintJson",
            data: a,
            success: function (msg) {
                var obj = msg;
                if (obj.success == true) {
                    data = obj.result;
                    var d = createTip(obj.result);
                    $("body").append(d);
                    for (var i = 0; i < obj.result.length; i++) {
                        if (obj.result[i].isShow == "0") {
                            //_this.hideCol(obj.data[i].columnCode);
                            //a.td[i].hide();
                        }
                    }
                    showHideTd();
                    if (func) {
                        func(obj.data);
                    }
                } else {
                    if (func) {
                        func(null);
                    }
                }
            }
        });
    }
    function saveSet() {
        var f = $(".column_set_div form");
        $.post("/Print/SetPrintJson", f.serialize(), function (data, status) {
            var obj = jQuery.parseJSON(data);
            if (obj.success == 'true' || obj.result == 'success') {

            } else {

            }
        });
        updateGridColSet();
        showHideTd();
    }
    function updateGridColSet() {
        $(".column_set_div form").find("input[name='isShow']").each(function (i) {
            var t = $(this).parent().find("input[name='setColumnId']").val();
            var n = $(this).parent().find("input[name='columnCode']").val();
            var v = $(this).val();
            for (var j = 0; j < data.length; j++) {
                if (data[j].setColumnId === t) {
                    data[j].isShow = v;
                    break;
                }
            }
            if (v == "0") {
                //gridUtil.hideCol(n);
            } else {
                //gridUtil.showCol(n);
            }
        });
    }
    function showOrHide(btn) {
        var v = $(btn).val();
        if (v == "隐藏收据") {
            $("tr[receiptMain='1']").hide();
            $("[mx_header='1']").show();
            $(btn).val("显示收据");
        } else {
            $("tr[receiptMain='1']").show();
            $("[mx_header='1']").hide();
            $(btn).val("隐藏收据");
        }
    }
    $(function () {
        $("[index]").hide();
        getColSet();
    });

    var loadInfo = function () {
        //$("#printObj").css({ "width": "270mm" });
        p_init(printInit);
    };
    $(function () {
        loadInfo();
    });

    function pageSet() {
        try {
            p_pagesetup();
        } catch (e) {
            wb.execwb(8, 1);
        }
    }
    function pageView() {
        try {
            p_preview();
        } catch (e) {
            wb.execwb(7, 1);
        }
    }
    function pagePrint() {
        try {
            p_print();
        } catch (e) {
            wb.execwb(6, 6);
        }
    }
</script>

